﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using GestorSQL.GUI.Properties;

namespace GestorSQL.GUI.Security
{
    public partial class LogInWindow : Form
    {
        #region Properties
        public bool IsAuthenticated { get; set; }

        public static bool IsLoggedIn
        {
            get { return LoginControl.IsLoggedIn; }
        }
        #endregion

        #region Cosntructors
        public LogInWindow()
        {
            IsAuthenticated = false;
            InitializeComponent();
        }
        #endregion

        #region Public Methods
        public static void Logout()
        {
            LoginControl.Logout();
        }
        #endregion

        #region Event Handlers
        private void lgcLogin_LoginEvent(object sender, LoginEventArgs e)
        {
            bool successful = e.Authenticated;
            if (successful == false)
            {
                MessageBox.Show(Resources.Security_BadUserOrPassword, Resources.Security_LoginText, MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
            else
            {
                IsAuthenticated = true;
                Close();
            }
        }

        private void LogInWindow_Load(object sender, EventArgs e)
        {
            this.AcceptButton = lgcLogin.btLogIn;
        }
        #endregion

    }
}
